/**
 * 客户
 * Created by wenchuan.li on 2018/6/14 11:16.
 */
define(function () {

    var self,
        app = win.app,
        orderSubmitArg,
        searchData = {
            keyword: ''
        }
    ;

    app.newModule({

        init: function () {
            self = this;
            self._super({
                _refreshAutoInit: true //自动加载刷新控件
            }, win);
            orderSubmitArg = self._pageParameters;
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat161/getGwakList",
                xdata: {
                    page: goods.page + 1,
                    limit: goods.limit,
                    GWAK006: '1',
                    keyword: searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        goods.data.pushArray(data.data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: '无客户信息...'
                        });
                    }
                }
            });
        },
        _search: function (data) {
            searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _lazy: function () {
            this._super();
            app.taps.call(win, [
                {
                    o: 'addBtn',
                    cb: function (e) {
                        app.openPage({
                            src: "base/customers-add.html",
                            args: {
                                cb: function () {
                                    self._refresh();
                                }
                            }
                        });
                    }
                }
            ]);
        },
        _ready: function () {
            Vue.component('customersitem', {
                template: app.getByid(doc, 'customersitem-template'),
                props: {
                    model: Array
                },
                methods: {
                    select: function (v) {
                        orderSubmitArg.cb(v);
                        app.back(1);
                    }
                }
            });
        }
    });

});